package org.easymis.crm.modules.system.controller;

import java.util.List;

import org.easymis.commons.web.BaseController;
import org.easymis.commons.web.utils.Page;
import org.easymis.commons.web.utils.R;
import org.easymis.crm.modules.system.entitys.mybatis.dto.OrganizeRole;
import org.easymis.crm.modules.system.service.OrganizeRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "组织角色管理")
@Controller
public class OrganizeRoleController extends BaseController {
	@Autowired
	OrganizeRoleService service;

	@ApiOperation(value = "角色管理首页", notes = "html", produces = MediaType.APPLICATION_JSON_VALUE)
	@RequestMapping(value = { "/organize/role/index.html" }, method = { RequestMethod.GET, RequestMethod.POST })
	public String index(@ModelAttribute Page page, ModelMap map) throws Exception {
		PageHelper.startPage(page.getCurPage(), page.getPageSize());
		List roleList = service.getList(new OrganizeRole());
		PageInfo<OrganizeRole> p = new PageInfo<OrganizeRole>(roleList);
		map.put("roleList", roleList);
		return getTplPath(map, "system/organize/role/index");
	}

	@ApiOperation(value = "角色分页列表", notes = "html", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	@RequestMapping(value = { "/organize/role/list.html" }, method = { RequestMethod.GET, RequestMethod.POST })
	public R list(@ModelAttribute Page page, ModelMap map) throws Exception {
		return new R().ok();
	}

	@ApiOperation(value = "角色分页列表", notes = "JSON ", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	@RequestMapping(value = { "/organize/role/list.json" }, method = { RequestMethod.GET, RequestMethod.POST })
	public R listJson(@ModelAttribute Page page, ModelMap map) throws Exception {
		PageHelper.startPage(page.getCurPage(), page.getPageSize());
		List roleList = service.getList(new OrganizeRole());
		PageInfo<OrganizeRole> p = new PageInfo<OrganizeRole>(roleList);
		return new R().put("pageInfo", p);
	}

	@ApiOperation(value = "添加", notes = "html", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	@RequestMapping(value = { "/organize/role/add.html" }, method = { RequestMethod.GET, RequestMethod.POST })
	public R forwardAdd(@ModelAttribute Page page, ModelMap map) throws Exception {
		return new R().ok();
	}

	@ApiOperation(value = "添加", notes = "JSON ", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	@RequestMapping(value = { "/organize/role/save.do" }, method = { RequestMethod.GET, RequestMethod.POST })
	public R save(@ModelAttribute Page page, ModelMap map, OrganizeRole bean) throws Exception {
		service.save(bean);
		return new R().ok();
	}

	@ApiOperation(value = "删除", notes = "JSON ", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	@RequestMapping(value = { "/organize/role/delete.do" }, method = { RequestMethod.GET, RequestMethod.POST })
	public R delete(@ModelAttribute Page page, ModelMap map, String roleId) throws Exception {
		service.delete(roleId);
		return new R().ok();
	}

	@ApiOperation(value = "编辑", notes = "html", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	@RequestMapping(value = { "/organize/role/edit.html" }, method = { RequestMethod.GET, RequestMethod.POST })
	public R forwardEdit(@ModelAttribute Page page, ModelMap map) throws Exception {
		return new R().ok();
	}

	@ApiOperation(value = "修改", notes = "JSON ", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	@RequestMapping(value = { "/organize/role/update.do" }, method = { RequestMethod.GET, RequestMethod.POST })
	public R update(@ModelAttribute Page page, ModelMap map) throws Exception {
		return new R().ok();
	}

	@ApiOperation(value = "详情", notes = "JSON ", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	@RequestMapping(value = { "/organize/role/view.json" }, method = { RequestMethod.GET, RequestMethod.POST })
	public R viewJson(@ModelAttribute Page page, ModelMap map, String roleId) throws Exception {
		OrganizeRole role = service.findById(roleId);
		return new R().put("role", role);
	}

	@ApiOperation(value = "详情", notes = "html", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	@RequestMapping(value = { "/organize/role/view.html" }, method = { RequestMethod.GET, RequestMethod.POST })
	public R view(@ModelAttribute Page page, ModelMap map, String roleId) throws Exception {
		OrganizeRole role = service.findById(roleId);
		return new R().put("role", role);
	}
}
